// https://leetcode.cn/problems/group-anagrams/submissions/

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        map<string, vector<string>> rec;
        for (int i = 0; i < strs.size(); ++i) {
            string key = strs[i];
            sort(key.begin(), key.end());
            rec[key].push_back(strs[i]);
        }
        vector<vector<string>> res;
        for (auto it = rec.begin(); it != rec.end(); ++it) {
            res.push_back(it->second);
        }
        return res;
    }
};